/**
 * Copyright 2012 Fonfon.Xen
 * All rights reserved.
 * 
 * @project 
 * @author Xen
 * @version 1.0
 * @data 2012-5-17
 */
package com.guidecaptain.java.action;

import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.guidecaptain.core.base.action.BaseAction;
import com.guidecaptain.java.model.pojo.Constellation;
import com.guidecaptain.java.service.ConstellationService;

/**
 * @author Xen
 * 
 */
@Controller
@Scope("prototype")
public class ConstellationAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Constellation constellation = new Constellation();
	@Autowired
	private ConstellationService constellationService;
	
	/**
	 * 添加
	 * @return
	 */
	public String creatConstellation() {
		
		if(constellationService.checkCslType(constellation.getCslType())){
			constellationService.updateConstellation(constellation);
		}else {
			constellationService.insertConstellation(constellation);
		}
		
		
		return "insert";
	}
	/**
	 * 删除
	 * @return
	 */
	public String delConstellation(){
		constellationService.queryConstellationById(constellation.getCslId());
		
		return "del";
	}
	
	/**
	 * 获得星座
	 * @return
	 */
	public String getConstellation(){
		try {
			PropertyUtils.copyProperties(constellation, constellationService.queryConstellationById(constellation.getCslId()));

		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
		
		return "bean";
	}
	
	/**
	 * 获得星座列表
	 * @return
	 */
	public String getConstellationList(){
		constellation.setConstellationList(constellationService.queryConstellationList(constellation));
		return "list";
	}
	
	/**
	 * @param
	 * @return
	 */
	@Override
	public Object getModel() {

		return constellation;
	}

}
